package io.github.banner.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.banner.service.UserService;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;
import java.util.UUID;

@Slf4j
@RestController
@RequestMapping
public class TestController {
    private static final String FLAG = "REQUEST_ID";
    @Resource
    private UserService userService;

    @GetMapping("/logTest")
    public void logTest() {
        log.debug("This class is : {}", TestController.class);
        log.info("This class is : {}", TestController.class);
        log.warn("This class is : {}", TestController.class);
        log.error("This class is : {}", TestController.class);
    }


    @SneakyThrows
    @PostMapping("/logTest2")
    public void logTest2(@RequestBody Map<String, String> data) {
        log.info("RequestBoy:[{}]", new ObjectMapper().writeValueAsString(data));
    }


    @GetMapping("/mdcTest")
    public void mdcTest() {
        MDC.put(FLAG, UUID.randomUUID().toString());
        log.info("MDC FLAG is : [{}]", MDC.get(FLAG));
        userService.createUser();
    }
}
